<template>
  <div class="app-container">
    <!--    <el-alert-->
    <!--      style="margin-bottom: 5px"-->
    <!--      title="以下为超出库存产品"-->
    <!--      type="warning"-->
    <!--      :closable="false">-->
    <!--    </el-alert>-->
    <el-form ref="queryForm" :model="queryParams" label-width="89px" v-show="showSearch" class="ele-form-search"
             @keyup.enter.native="reload"
             @submit.native.prevent>
      <el-row :gutter="15">
        <el-col :lg="8" :md="12">
          <!--          <el-form-item label="物
          料编码" prop="materialCode">-->
          <!--            <el-input-->
          <!--              v-model="queryParams.materialCode"-->
          <!--              placeholder="请输入产品编码"-->
          <!--              clearable-->
          <!--              @keyup.enter.native="handleQuery"-->
          <!--            />-->
          <!--          </el-form-item>-->
        </el-col>
        <el-col :lg="8" :md="12">
          <el-form-item label="产品名称" prop="materialName">
            <el-input
              v-model="queryParams.materialName"
              placeholder="请输入产品名称"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <!--        <el-col :lg="8" :md="12">-->

        <!--        </el-col>-->
        <!--        <el-col :lg="8" :md="12">-->
        <!--          <el-form-item label="库区编号" prop="reservoirNumber">-->
        <!--            <el-input-->
        <!--              v-model="queryParams.reservoirNumber"-->
        <!--              placeholder="请输入库区编号"-->
        <!--              clearable-->
        <!--              @keyup.enter.native="handleQuery"-->
        <!--            />-->
        <!--          </el-form-item>-->
        <!--        </el-col>-->
        <!--        <el-col :lg="8" :md="12">-->
        <!--          <el-form-item label="库存数量" prop="nventoryQuantity">-->
        <!--            <el-input-->
        <!--              v-model="queryParams.nventoryQuantity"-->
        <!--              placeholder="请输入库存数量"-->
        <!--              clearable-->
        <!--              @input="aa"-->
        <!--              @keyup.enter.native="handleQuery"-->
        <!--            />-->
        <!--          </el-form-item>-->
        <!--        </el-col>-->
        <!--        <el-col :lg="8" :md="12">-->
        <!--          <el-form-item label="批次号" prop="batchNumber">-->
        <!--            <el-input-->
        <!--              v-model="queryParams.batchNumber"-->
        <!--              placeholder="请输入批次号"-->
        <!--              clearable-->
        <!--              @keyup.enter.native="handleQuery"-->
        <!--            />-->
        <!--          </el-form-item>-->
        <!--        </el-col>-->
        <!--        <el-col :lg="8" :md="12">-->
        <!--          <el-form-item label="生产日期" prop="productionDate">-->
        <!--            <el-date-picker clearable-->
        <!--                            v-model="queryParams.productionDate"-->
        <!--                            type="date"-->
        <!--                            value-format="yyyy-MM-dd"-->
        <!--                            placeholder="请选择生产日期">-->
        <!--            </el-date-picker>-->
        <!--          </el-form-item>-->
        <!--        </el-col>-->
        <!--&lt;!&ndash;        <el-col :lg="8" :md="12">&ndash;&gt;-->
        <!--&lt;!&ndash;          <el-form-item label="有效天数" prop="validDays">&ndash;&gt;-->
        <!--&lt;!&ndash;            <el-input&ndash;&gt;-->
        <!--&lt;!&ndash;              v-model="queryParams.validDays"&ndash;&gt;-->
        <!--&lt;!&ndash;              placeholder="请输入有效天数"&ndash;&gt;-->
        <!--&lt;!&ndash;              clearable&ndash;&gt;-->
        <!--&lt;!&ndash;              @input="bb"&ndash;&gt;-->
        <!--&lt;!&ndash;              @keyup.enter.native="handleQuery"&ndash;&gt;-->
        <!--&lt;!&ndash;            />&ndash;&gt;-->
        <!--&lt;!&ndash;          </el-form-item>&ndash;&gt;-->
        <!--&lt;!&ndash;        </el-col>&ndash;&gt;-->
        <!--        <el-col :lg="8" :md="12">-->
        <!--          <el-form-item label="有效期" prop="validity">-->
        <!--            <el-date-picker clearable-->
        <!--                            v-model="queryParams.validity"-->
        <!--                            type="date"-->
        <!--                            value-format="yyyy-MM-dd"-->
        <!--                            placeholder="请选择有效期">-->
        <!--            </el-date-picker>-->
        <!--          </el-form-item>-->
        <!--        </el-col>-->
        <!--        <el-col :lg="8" :md="12">-->
        <!--          &lt;!&ndash;          <el-form-item label="订单号" prop="rderNumber">&ndash;&gt;-->
        <!--          &lt;!&ndash;            <el-input&ndash;&gt;-->
        <!--          &lt;!&ndash;              v-model="queryParams.rderNumber"&ndash;&gt;-->
        <!--          &lt;!&ndash;              placeholder="请输入订单号"&ndash;&gt;-->
        <!--          &lt;!&ndash;              clearable&ndash;&gt;-->
        <!--          &lt;!&ndash;              @keyup.enter.native="handleQuery"&ndash;&gt;-->
        <!--          &lt;!&ndash;            />&ndash;&gt;-->
        <!--          &lt;!&ndash;          </el-form-item>&ndash;&gt;-->
        <!--        </el-col>-->
        <!--        <el-col :lg="8" :md="12">-->
        <!--          &lt;!&ndash;          <el-form-item label="创建人" prop="createUser">&ndash;&gt;-->
        <!--          &lt;!&ndash;            <el-input&ndash;&gt;-->
        <!--          &lt;!&ndash;              v-model="queryParams.createUser"&ndash;&gt;-->
        <!--          &lt;!&ndash;              placeholder="请输入创建人"&ndash;&gt;-->
        <!--          &lt;!&ndash;              clearable&ndash;&gt;-->
        <!--          &lt;!&ndash;              @keyup.enter.native="handleQuery"&ndash;&gt;-->
        <!--          &lt;!&ndash;            />&ndash;&gt;-->
        <!--          &lt;!&ndash;          </el-form-item>&ndash;&gt;-->
        <!--        </el-col>-->
        <el-col :lg="8" :md="12">
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-col>
      </el-row>

    </el-form>

    <!--    <el-row :gutter="10" class="mb8">-->
    <!--      &lt;!&ndash;      <el-col :span="1.5">&ndash;&gt;-->
    <!--      &lt;!&ndash;        <el-button&ndash;&gt;-->
    <!--      &lt;!&ndash;          type="primary"&ndash;&gt;-->
    <!--      &lt;!&ndash;          plain&ndash;&gt;-->
    <!--      &lt;!&ndash;          icon="el-icon-plus"&ndash;&gt;-->
    <!--      &lt;!&ndash;          size="mini"&ndash;&gt;-->
    <!--      &lt;!&ndash;          @click="handleAdd"&ndash;&gt;-->
    <!--      &lt;!&ndash;          v-hasPermi="['wareManagement:inventoryInquiry:add']"&ndash;&gt;-->
    <!--      &lt;!&ndash;        >新增&ndash;&gt;-->
    <!--      &lt;!&ndash;        </el-button>&ndash;&gt;-->
    <!--      &lt;!&ndash;      </el-col>&ndash;&gt;-->
    <!--      &lt;!&ndash;      <el-col :span="1.5">&ndash;&gt;-->
    <!--      &lt;!&ndash;        <el-button&ndash;&gt;-->
    <!--      &lt;!&ndash;          type="success"&ndash;&gt;-->
    <!--      &lt;!&ndash;          plain&ndash;&gt;-->
    <!--      &lt;!&ndash;          icon="el-icon-edit"&ndash;&gt;-->
    <!--      &lt;!&ndash;          size="mini"&ndash;&gt;-->
    <!--      &lt;!&ndash;          :disabled="single"&ndash;&gt;-->
    <!--      &lt;!&ndash;          @click="handleUpdate"&ndash;&gt;-->
    <!--      &lt;!&ndash;          v-hasPermi="['wareManagement:inventoryInquiry:edit']"&ndash;&gt;-->
    <!--      &lt;!&ndash;        >修改&ndash;&gt;-->
    <!--      &lt;!&ndash;        </el-button>&ndash;&gt;-->
    <!--      &lt;!&ndash;      </el-col>&ndash;&gt;-->
    <!--      &lt;!&ndash;      <el-col :span="1.5">&ndash;&gt;-->
    <!--      &lt;!&ndash;        <el-button&ndash;&gt;-->
    <!--      &lt;!&ndash;          type="danger"&ndash;&gt;-->
    <!--      &lt;!&ndash;          plain&ndash;&gt;-->
    <!--      &lt;!&ndash;          icon="el-icon-delete"&ndash;&gt;-->
    <!--      &lt;!&ndash;          size="mini"&ndash;&gt;-->
    <!--      &lt;!&ndash;          :disabled="multiple"&ndash;&gt;-->
    <!--      &lt;!&ndash;          @click="handleDelete"&ndash;&gt;-->
    <!--      &lt;!&ndash;          v-hasPermi="['wareManagement:inventoryInquiry:remove']"&ndash;&gt;-->
    <!--      &lt;!&ndash;        >删除&ndash;&gt;-->
    <!--      &lt;!&ndash;        </el-button>&ndash;&gt;-->
    <!--      &lt;!&ndash;      </el-col>&ndash;&gt;-->
    <!--      <el-col :span="1.5">-->
    <!--        &lt;!&ndash;        <el-button&ndash;&gt;-->
    <!--        &lt;!&ndash;          type="warning"&ndash;&gt;-->
    <!--        &lt;!&ndash;          plain&ndash;&gt;-->
    <!--        &lt;!&ndash;          icon="el-icon-download"&ndash;&gt;-->
    <!--        &lt;!&ndash;          size="mini"&ndash;&gt;-->
    <!--        &lt;!&ndash;          @click="handleExport"&ndash;&gt;-->
    <!--        &lt;!&ndash;          v-hasPermi="['wareManagement:inventoryInquiry:export']"&ndash;&gt;-->
    <!--        &lt;!&ndash;        >导出&ndash;&gt;-->
    <!--        &lt;!&ndash;        </el-button>&ndash;&gt;-->
    <!--      </el-col>-->
    <!--      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>-->
    <!--    </el-row>-->

    <el-table v-loading="loading" :data="listA" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="产品名称" align="center" prop="materialName" width="200"
                       show-overflow-tooltip></el-table-column>
      <el-table-column label="产品编码" align="center" prop="materialCode"></el-table-column>
      <el-table-column label="库存数量" align="center" prop="inventoryDifference"></el-table-column>
      <el-table-column label="单位" align="center" prop="unit"></el-table-column>
      <!--      <el-table-column label="批次号" align="center" prop="batchNumber"></el-table-column>-->
      <!--      <el-table-column label="生产日期" align="center" prop="productionDate"></el-table-column>-->
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getListA"
    />

    <!-- 添加或修改库存查询对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-row :gutter="15">
          <el-col :lg="12" :md="24">
            <el-form-item label="产品编码" prop="materialCode">
              <el-input v-model="form.materialCode" placeholder="请输入产品编码"/>
            </el-form-item>
          </el-col>
          <el-col :lg="12" :md="24">
            <el-form-item label="产品名称" prop="materialName">
              <el-input v-model="form.materialName" placeholder="请输入产品名称"/>
            </el-form-item>
          </el-col>
          <el-col :lg="12" :md="24">
            <el-form-item label="库位编号" prop="materialNumber">
              <el-input v-model="form.materialNumber" placeholder="请输入库位编号"/>
            </el-form-item>
          </el-col>
          <el-col :lg="12" :md="24">
            <el-form-item label="库区编号" prop="reservoirNumber">
              <el-input v-model="form.reservoirNumber" placeholder="请输入库区编号"/>
            </el-form-item>
          </el-col>
          <el-col :lg="12" :md="24">
            <el-form-item label="库存数量" prop="nventoryQuantity">
              <el-input @input="cc" v-model="form.nventoryQuantity" placeholder="请输入库存数量"/>
            </el-form-item>
          </el-col>
          <el-col :lg="12" :md="24">
            <el-form-item label="单位" prop="unit">
              <el-input v-model="form.unit" placeholder="请输入单位"/>
            </el-form-item>
          </el-col>
          <el-col :lg="12" :md="24">
            <el-form-item label="批次号" prop="batchNumber">
              <el-input v-model="form.batchNumber" placeholder="请输入批次号"/>
            </el-form-item>
          </el-col>
          <el-col :lg="12" :md="24">
            <el-form-item label="库存状态" prop="stockStatus">
              <el-input v-model="form.stockStatus" placeholder="请输入库存状态"/>
            </el-form-item>
          </el-col>
          <el-col :lg="12" :md="24">
            <el-form-item label="生产日期" prop="productionDate">
              <el-date-picker clearable
                              v-model="form.productionDate"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="请选择生产日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :lg="12" :md="24">
            <el-form-item label="有效天数" prop="validDays">
              <el-input @input="dd" v-model="form.validDays" placeholder="请输入有效天数"/>
            </el-form-item>
          </el-col>
          <el-col :lg="12" :md="24">
            <el-form-item label="有效期" prop="validity">
              <el-date-picker clearable
                              v-model="form.validity"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="请选择有效期">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :lg="12" :md="24">
            <el-form-item label="产品名称" prop="supplierName">
              <el-input v-model="form.supplierName" placeholder="请输入产品名称"/>
            </el-form-item>
          </el-col>
          <el-col :lg="12" :md="24">
            <el-form-item label="订单号" prop="rderNumber">
              <el-input v-model="form.rderNumber" placeholder="请输入订单号"/>
            </el-form-item>
          </el-col>
          <el-col :lg="12" :md="24">
            <el-form-item label="创建人" prop="createUser">
              <el-input v-model="form.createUser" placeholder="请输入创建人"/>
            </el-form-item>
          </el-col>
          <el-col :lg="12" :md="24">
            <el-form-item label="最后更新人" prop="lastUpdater">
              <el-input v-model="form.lastUpdater" placeholder="请输入最后更新人"/>
            </el-form-item>
          </el-col>
          <el-col :lg="12" :md="24">
            <el-form-item label="最后更新时间" prop="lastUpdateTime">
              <el-date-picker clearable
                              v-model="form.lastUpdateTime"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="请选择最后更新时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listInventoryInquiry,
  getInventoryInquiry,
  delInventoryInquiry,
  addInventoryInquiry,
  updateInventoryInquiry
} from "@/api/wareManagement/inventoryInquiry";
import {
  listMaterialManagement
} from "@/api/basicData/materialManagement";
import {Warning} from "@/api/qualityManagement/qualityInspection";

export default {
  name: "InventoryInquiry",
  data() {
    return {
      listA: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 库存查询表格数据
      inventoryInquiryList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 20,
        materialCode: null,
        materialName: null,
        materialNumber: null,
        reservoirNumber: null,
        nventoryQuantity: null,
        unit: null,
        batchNumber: null,
        stockStatus: null,
        productionDate: null,
        validDays: null,
        validity: null,
        supplierName: null,
        rderNumber: null,
        createUser: null,
        lastUpdater: null,
        lastUpdateTime: null
      },
      //产品id
      idD: [],
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        materialCode: [
          {required: true, message: "产品编码不能为空", trigger: "blur"}
        ],
      }
    };
  },
  created() {
    this.getListA()
  },
  computed: {
    filteredInventoryInquiryList() {
      return this.inventoryInquiryList.filter(row => {
        return row.minimumStock !== null && row.maximumInventory !== null && row.inventoryDifference > row.maximumInventory;
      });
    }
  },
  mounted() {
    // this.getwuliaoList();
  },
  methods: {
    // tableRowClassName({row, rowIndex}) {
    //   if (row.minimumStock === null || row.maximumInventory === null) {
    //     return '';
    //   } else if (row.inventoryDifference > row.maximumInventory) {
    //     return 'success-row';
    //   } else if (row.inventoryDifference < row.minimumStock) {
    //     return 'warning-row';
    //   } else {
    //     return '';
    //   }
    // },
    // getTooltipContent(row) {
    //   if (row.minimumStock === null || row.maximumInventory === null) {
    //     return '未设置最高或是最低';}
    //   else if (row.inventoryDifference > row.maximumInventory) {
    //     return '库存过剩';
    //   } else if (row.inventoryDifference < row.minimumStock) {
    //     return '库存过低';
    //   }else {
    //     return '水位安全';
    //   }
    //
    // },
    // 获取超出物料
    getListA() {
      this.loading = true
      Warning().then(res => {
        //console.log(res.rows, 'data')
        this.loading = false
        this.listA = res.rows
        this.total = res.total;
        this.loading = false;
      })
    },
    /** 查询产品管理列表 */
    // getwuliaoList() {
    //   listMaterialManagement().then(response => {
    //     this.loading = false
    //     const materialManagementList = response.rows;
    //     this.idD = materialManagementList.map(item => item.materialId);
    //     this.idD = this.idD.join("，")
    //     //console.log("idsss", this.idD); // 使用 this.idD
    //     if (this.idD.length) {
    //       this.getList();
    //     }
    //   });
    // },
    aa(value) {
      this.queryParams.nventoryQuantity = value.replace(/\D/g, '');
    },
    cc(value) {
      this.form.nventoryQuantity = value.replace(/\D/g, '');
    },
    bb(value) {
      this.queryParams.validDays = value.replace(/\D/g, '');
    },
    dd(value) {
      this.form.validDays = value.replace(/\D/g, '');
    },
    /** 查询库存查询列表 */
    // getList() {
    //   this.loading = true;
    //   this.queryParams.materialId = this.idD
    //   //console.log("898989898989898", this.queryParams)
    //   listInventoryInquiry(this.queryParams).then(response => {
    //     this.inventoryInquiryList = response.rows;
    //     //console.log('list', response)
    //     this.total = response.total;
    //     this.loading = false;
    //
    //   });
    // },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        inquiryId: null,
        materialCode: null,
        materialName: null,
        materialNumber: null,
        reservoirNumber: null,
        nventoryQuantity: null,
        unit: null,
        batchNumber: null,
        stockStatus: null,
        productionDate: null,
        validDays: null,
        validity: null,
        supplierName: null,
        rderNumber: null,
        createUser: null,
        createTime: null,
        lastUpdater: null,
        lastUpdateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      console.log(this.queryParams)
      Warning(this.queryParams).then(res => {
        // console.log(res)
        this.listA = res.rows
      })
      this.queryParams.pageNum = 1;
      // this.getListA();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.getListA();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.inquiryId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加库存查询";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const inquiryId = row.inquiryId || this.ids
      getInventoryInquiry(inquiryId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改库存查询";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.inquiryId != null) {
            updateInventoryInquiry(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addInventoryInquiry(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const inquiryIds = row.inquiryId || this.ids;
      this.$modal.confirm('是否确认删除库存查询编号为"' + inquiryIds + '"的数据项？').then(function () {
        return delInventoryInquiry(inquiryIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
  }
}
;
</script>
<style>
.el-table .warning-row {
  background: oldlace;
}

.el-table .success-row {
  background: #e642426b;
}
</style>
